"""

"""
import requests

# 发送get请求
url = "http://127.0.0.1:8088/futureloan/mvc/api/member/login?mobilephone=18012345670&pwd=123456"
r = requests.get(url)  # 发送请求，获取响应
print(r.text)  # 文本格式的响应体
print(r.json())  # 获取json格式的响应体
print(r.json()['msg'])  # 根据key获取value
assert r.json()['msg'] == "登录成功"
assert r.json()['code'] == "10001"

# 2.发送get请求，参数组装成字典，使用params参数传递
url = "http://127.0.0.1:8088/futureloan/mvc/api/member/login"
cs = {"mobilephone": "18012345670", "pwd": "123456"}
r = requests.get(url, params=cs)
assert r.json()['msg'] == "登录成功"
assert r.json()['code'] == "10001"

# post:表单格式参数 data
# 金融充值接口
url = "http://127.0.0.1:8088/futureloan/mvc/api/member/recharge"
r = requests.post(url, data={'mobilephone': '18012345670', 'amount': '1200.54'})
print(r.text)  # 文本格式的响应体
print(r.json())  # 获取json格式的响应体
assert r.json()['msg'] == '充值成功'

# post:json 格式参数，json传参
# 学之思登录接口
url = "http://127.0.0.1:8000/api/user/login"
r = requests.post(url, json={'userName': 'admin', 'password': '123456', 'remember': False})
print(r.text)
print(r.json())
assert r.json()['message'] == '成功'

# 上传文件
url = "http://192.168.1.14:8088/carRental/file/uploadFile.action"
path = r"C:\Users\卫洋盼\Desktop\微信图片_20240405103223.jpg"
with open(path, 'rb') as f:
    # cs = {'mf':(path,f)}  # {'name':('filename',fileobj)}
    cs = {'mf': (path, f, "image/jpeg")}  # {'name':('filename',fileobj,content_typr)}

    r = requests.post(url, files=cs)
    print(r.json())
    src = r.json()['data']['src']
    print("图片在服务器上的路径", src)

    print("状态码", r.status_code)
    print("响应头", r.headers)
    print("请求头", r.request.headers)

    # 伪装成浏览器发送的请求
    hd = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                        "Chrome/126.0.0.0 Safari/537.36"}
    r = requests.post(url, files=cs, headers=hd)
    print("请求头", r.request.headers)

f.close()
